package com.smartstate.ems.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartstate.ems.entity.Alarm;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface AlarmMapper extends BaseMapper<Alarm> {

    /**
     * 拿到设备id 和 设属性 判断是否关闭报警
     */
    @Update("update alarm set state = '1',remark  = #{remark} , stopTime= #{stopTime} where deviceId = #{deviceId} and attributes =#{attributes} and state = '2'")
    int updateAlarmAttributes(String deviceId,String attributes,String remark,String stopTime);

    /**
     * 根据deviceId，attributes，state判断是否有这个报警
     * @param deviceId
     * @param attributes
     * @return
     */
    @Select("select count(*) from  alarm where deviceId = #{deviceId} and attributes =#{attributes} and state != #{state}")
    int countAlarm(String deviceId,String attributes,Integer state);

    @Update("update alarm set state = '1',remark  = #{remark} , stopTime= #{stopTime} where deviceId = #{deviceId} and attributes =#{attributes} ")
    int offAlarm(String deviceId,String attributes,String remark,String stopTime);
}
